iT邦幫忙

2024 iThome 鐵人賽

DAY 6
0

今天跑去聽演唱會,完全忘記要來發文,太慘惹,我好蠢QQ
要能時時刻刻記得自己有在進行鐵人賽的參賽者們真的很不簡單
明年真的要確實提早準備,還要記得每天訂鬧鐘提醒自己
總之還是把該做的事情繼續完成ㄅ


這集也是陣列方法的處理

Q1

  • 是否至少有 1 人年滿 19 歲
people.some((person) => currentYear - person.year >= 19)

Q2

  • 是否全員都滿 19 歲
people.every((person) => currentYear - person.year >= 19)

Q3

  • 找出特定 ID 的人員資料
comments.find((comment) => comment.id === "823423")

Q4

  • 找出特定 ID 的索引
comments.findIndex((comment) => comment.id === "823423")

Q5

  • 刪除特定 ID 的資料
const index = comments.findIndex((comment) => comment.id === "823423");
return [...comments.slice(0, index), ...comments.slice(index + 1)];

DEMO

https://codesandbox.io/p/devbox/day07-array-cardio-day2-dmw6vh

總結

  • splice() 可以對陣列進行修剪

  • slice() 則是會回傳新的陣列,不會修改原始資料


上一篇
[Day06]_Type-Ahead
下一篇
[Day08]_Canvas
系列文
React30——用 React 探索 JavaScript30 的魅力10
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言